home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3593 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.1 KB

  1. Path: news1.h1.usa.pipeline.com!usenet
  2. From: grantp@usa.pipeline.com(Pete)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: I Need HELP!
  5. Date: 25 Jan 1996 00:21:21 GMT
  6. Organization: Kalevi, Inc.
  7. Message-ID: <4e6ie1$5qi@news1.usa.pipeline.com>
  8. NNTP-Posting-Host: pipe3.h1.usa.pipeline.com
  9. X-PipeUser: grantp
  10. X-PipeHub: usa.pipeline.com
  11. X-PipeGCOS: (Pete)
  12. X-Newsreader: Pipeline USA v3.3.0
  13.  
  14. On Jan 24, 1996 23:08:44 in article <I Need HELP!>,
  15. 'jeremyx@ix.netcom.com(Jeremy Johnston )' wrote: 
  16.  
  17. >Does anyone know how do get character input use the goto statement? 
  18. >example,I cant get this to work: 
  19. >________________________ 
  20. >main() 
  21. >{ 
  22. >char ch; 
  23. >getchar(); 
  24.  
  25. Well, the compiler's kind of dumb.  It doesn't realize that it should 
  26. do what you want, not what you say.  My guess is that you would 
  27. prefer that the character read in by getchar() be placed into 
  28. the variable ch, as it would be the only thing that would make 
  29. any sense, given the code you supplied.  So, you should write: 
  30.  
  31.     ch = getchar(); 
  32.  
  33.  
  34. >if (ch==q)  
  35.  
  36. Hmm. what's q?  My guess is that you meant the character 'q' 
  37. rather than some undeclared variable named q.  So, try putting 
  38. single quotes around the q, then the code might even compile. 
  39.  
  40. >goto b; 
  41. I'm at a loss as to what you intended here.  As you may know, 
  42. instructions you give to the computer are executed in sequence, 
  43. left to right, top to bottom, unless you direct otherwise.  The goto  
  44. keyword is such a direction.  But, let's analyze this.  If ch == 'q'  
  45. the computer is directed to jump to the statement labelled b, and  
  46. the computer will print "it worked" on its standard output device,  
  47. the screen in most cases. 
  48.  
  49. But if the user didn't enter a 'q', then the computer will skip 
  50. the goto instruction and drop down to the next one.  Lo and 
  51. behold, the next instruction is the one labelled b and, once 
  52. again, you get "it worked".  Is that what you intended? 
  53. Probably not. 
  54.  
  55. >b:printf("it worked"); 
  56. >} 
  57. >_______________________ 
  58. >Why doesn't this work? 
  59.  
  60. Now you know. :-) 
  61. -- 
  62. Pete Grant 
  63. Kalevi, Inc. 
  64. Object Oriented Software Development
  65.